
$(document).ready(function() {
    new postik("Study for final exams");
    new postik("Got to the dentist", "blue");
    new postik("Feed the cat");
    new postik("Feed the other cat", "green");
    new postik("Conquer the World");
    new postik("Hello postik!", "pink");
    new postik("Really small but high task", null, 40, 200);
    new postik("The best postik in the quantum galaxy full of really slow neutrins", null, 220);

    var form = document.createElement("form");
    var input = document.createElement("input");
    form.appendChild(input);
    $(form).submit(function() {
        new postik($(input).attr("value"));
        return false;
    });
    document.body.appendChild(form);
});

postik = function(text, color, width, height) {
    // Attributes
    this.color = "yellow";

    // Methods
    this.getColor = function() {
        return this.color;
    };
    this.setColor = function (c) {
        this.color = c;
        if (c) {
            $(this.postikDiv).addClass("postik_" + c);
        }
    };

    this.postikDiv = document.createElement('div');
    $(this.postikDiv).addClass("postik");
    $(this.postikDiv).text(text);
    this.setColor(color);
    $(this.postikDiv).css("width", width || "80px");
    if (height) {
        $(this.postikDiv).css("height", height);
    }
    document.body.appendChild(this.postikDiv);
    $(this.postikDiv).draggable().resizable();
};

